package sz.szsmk.citizencard.ui.adapter;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryMetroExitInfoRes;
import sz.szsmk.citizencard.ui.activity.SubwaySiteDetailActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/11 10:36
 * description:
 */
public class SubwaySiteAdapter extends RecyclerView.Adapter<SubwaySiteAdapter.SubwaySiteHolder> {
    private SubwaySiteDetailActivity mContext;
    private List<QueryMetroExitInfoRes.MetroExtraInfoListBean.StandExtraListBean> viewData;

    public SubwaySiteAdapter(SubwaySiteDetailActivity context) {
        mContext = context;
    }

    @Override
    public SubwaySiteHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.subway_site_detail_item, parent, false);
        return new SubwaySiteHolder(view);
    }

    @Override
    public void onBindViewHolder(SubwaySiteHolder holder, int position) {
        if (viewData != null) {
            holder.openName.setText(viewData.get(position).getMetro_extra_name());
            LinearLayoutManager manager = new LinearLayoutManager(mContext);
            holder.openRv.setLayoutManager(manager);
            SubwayOpenAdapter openAdapter = new SubwayOpenAdapter(mContext);
            holder.openRv.setAdapter(openAdapter);
            openAdapter.setViewData(viewData.get(position).getStandExtraOfficeList());
            openAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryMetroExitInfoRes.MetroExtraInfoListBean.StandExtraListBean> viewData) {
        this.viewData = viewData;
    }

    public static class SubwaySiteHolder extends RecyclerView.ViewHolder {


        private final RecyclerView openRv;
        private final TextView openName;

        public SubwaySiteHolder(View itemView) {
            super(itemView);
            openRv = (RecyclerView) itemView.findViewById(R.id.subway_open_rv);
            openName = (TextView) itemView.findViewById(R.id.open_name);
//            TextView textView = (TextView) itemView.findViewById(R.id.text_1);
        }
    }

}
